package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TXiaohaoEntity;
import com.company.project.service.TXiaohaoService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-10-27 11:04:08
 */
@Controller
@RequestMapping("/")
public class TXiaohaoController {
    @Autowired
    private TXiaohaoService tXiaohaoService;
    /**
    * 跳转到页面
    */
    @GetMapping("/index/tXiaohao/{tseatsid}")
    public String tXiaohao(Model model, @PathVariable("tseatsid") String tseatsid) {
        model.addAttribute("tseatsid",tseatsid);
        return "txiaohao/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("tXiaohao/add")
    //@RequiresPermissions("tXiaohao:add")
    @ResponseBody
    public DataResult add(@RequestBody TXiaohaoEntity tXiaohao){
        return tXiaohaoService.add(tXiaohao);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tXiaohao/delete")
    @RequiresPermissions("tXiaohao:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tXiaohaoService.delete(ids);

        tXiaohaoService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tXiaohao/update")
    @RequiresPermissions("tXiaohao:update")
    @ResponseBody
    public DataResult update(@RequestBody TXiaohaoEntity tXiaohao){
        tXiaohaoService.updateById(tXiaohao);
        return DataResult.success();
    }

    @ApiOperation(value = "禁用")
    @PutMapping("tXiaohao/updateState")
//    @RequiresPermissions("tXiaohao:update")
    @ResponseBody
    public DataResult updateState(@RequestBody TXiaohaoEntity tXiaohao){
        tXiaohaoService.updateById(tXiaohao);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tXiaohao/listByPage")
    @LogAnnotation(title = "小号", action = "查询分页数据")
    //@RequiresPermissions("tXiaohao:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TXiaohaoEntity tXiaohao){
        Page page = new Page(tXiaohao.getPage(), tXiaohao.getLimit());
        LambdaQueryWrapper<TXiaohaoEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件
        queryWrapper.eq(TXiaohaoEntity::getTseatsid, tXiaohao.getTseatsid());
        IPage<TXiaohaoEntity> iPage = tXiaohaoService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }
    @ApiOperation(value = "查询分页数据")
    @GetMapping("tXiaohao/listByTseatsId")
    //@RequiresPermissions("tXiaohao:list")
    public String findList(Model model,String tseatsid){
        model.addAttribute("tseatsid", tseatsid);
        return "txiaohao/list";
    }

}
